//
//  MineContentListCellTableViewCell.m
//  WeCommunity
//
//  Created by mac on 2017/6/15.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "MineContentListCell.h"
#import "MineContentListModel.h"


@interface MineContentListCell ()

@property (nonatomic,strong) UIImageView * contentImage;

@property (nonatomic,strong) UIImageView * arrowImage;

@property (nonatomic,strong) UILabel * contentLabel;

@property (nonatomic,strong) UILabel * detailLabel;

@property (nonatomic,strong) UIView * lineView;

@property (nonatomic,strong) UIView * topLineView;

@property (nonatomic,strong) UIView * botLineView;

@end


@implementation MineContentListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        CGFloat height = 44;
        
        self.contentImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, height / 2 - 14, 28, 28)];
        self.contentImage.contentMode = UIViewContentModeScaleAspectFit;
        self.contentImage.clipsToBounds = YES;
        [self.contentView addSubview:self.contentImage];
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.contentImage.frame) + 15, height / 2 - 12, 200, 24)];
        self.contentLabel.textColor = [UIColor blackColor];
        self.contentLabel.font = PFR_FONT(16);
        [self.contentView addSubview:self.contentLabel];
        
        self.arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(KScreen_Width - 22, height / 2 - 8, 10, 17)];
        self.arrowImage.contentMode = UIViewContentModeScaleAspectFill;
        self.arrowImage.clipsToBounds = YES;
        self.arrowImage.image = [UIImage imageNamed:@"arrow_right"];
        [self.contentView addSubview:self.arrowImage];
        
        self.lineView = [[UIView alloc] initWithFrame:CGRectMake(15, height - 0.5, KScreen_Width - 15, 0.5)];
        self.lineView .backgroundColor = LINE_COLOR;
        [self.contentView addSubview:self.lineView ];
        
        self.topLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreen_Width, 0.5)];
        self.topLineView .backgroundColor = LINE_COLOR;
        [self.contentView addSubview:self.topLineView ];
        
        self.botLineView = [[UIView alloc] initWithFrame:CGRectMake(0, height - 0.5, KScreen_Width, 0.5)];
        self.botLineView .backgroundColor = LINE_COLOR;
        [self.contentView addSubview:self.botLineView ];
        
        /**
         *
         */
        
        self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScreen_Width - 235, height / 2 - 12, 200, 24)];
        self.detailLabel.textAlignment = NSTextAlignmentRight;
        self.detailLabel.textColor = HH_COLOR_RGB(134, 134, 134);
        self.detailLabel.font = PFR_FONT(14);
        [self.contentView addSubview:self.detailLabel];
//        self.detailLabel.hidden = YES;
        
    }
    return self;
}


-(void)creatCellWithModel:(id )model
{
    MineContentListModel * contentModel = model;
    self.contentImage.image = contentModel.contentImage;
    self.contentLabel.text = contentModel.contentName;
    self.detailLabel.text = contentModel.detail;
}

-(void)showMineInfoCellWithModel:(id )model
{
    MineContentListModel * contentModel = model;
    
    if (contentModel.mark == 1) {
        
        CGFloat height = 44;
        
        self.contentLabel.frame = CGRectMake(15, height / 2 - 12, 150, 24);
        self.contentLabel.text = contentModel.contentName;
        
        self.detailLabel.hidden = NO;
        self.detailLabel.text = contentModel.detail;
        
        self.contentImage.hidden = YES;
        
        self.botLineView.frame = CGRectMake(0, height - 0.5, KScreen_Width, 0.5);
        
    }else if (contentModel.mark == 0){
        
        CGFloat height = 88;
        
        self.contentLabel.frame = CGRectMake(15, height / 2 - 12, 150, 24);
        self.contentLabel.text = contentModel.contentName;
        
        self.detailLabel.hidden = YES;
        
        self.contentImage.hidden = NO;
        self.contentImage.frame = CGRectMake(KScreen_Width - 100, height / 2 - 33, 66, 66);
        self.contentImage.layer.cornerRadius = 6.0;
        self.contentImage.contentMode = UIViewContentModeScaleAspectFill;
        self.contentImage.clipsToBounds = YES;
        [self.contentImage sd_setImageWithURL:LOADINGTHUMBIMG_FIXED_URL(contentModel.detail)
                             placeholderImage:[UIImage imageNamed:@"placeholder"]
                                      options:SDWebImageRetryFailed
                                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                        
                                    }];
        
        
        self.botLineView.frame = CGRectMake(0, height - 0.5, KScreen_Width, 0.5);
        self.arrowImage.frame = CGRectMake(KScreen_Width - 22, height / 2 - 8, 10, 17);
    }
}

-(void)needAddTopLine:(BOOL)topLine addBottomLine:(BOOL)bottomLine
{
    self.topLineView.hidden = !topLine;
    
    self.lineView.hidden = bottomLine;
    self.botLineView.hidden = !bottomLine;
}



@end
